package com.fenghongzhang.day009;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;


/**
 * A simple {@link Fragment} subclass.
 */
public class BlankFragment2 extends Fragment {
    private Button bbtn;

    private Main2Activity activity;
    public BlankFragment2() {
        // Required empty public constructor
    }


    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        activity = (Main2Activity) getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_blank2, container, false);

        bbtn = (Button) inflate.findViewById(R.id.bbtn);

        //点击跳转到第一个fragment,并修改第一个fragment中组件的值.
        bbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //得到所有fragment的集合,get(0),是得到第一个.
                Button viewById = getFragmentManager().getFragments().get(0).getView().findViewById(R.id.btn);
                viewById.setText("呵呵呵呵");
                activity.senPage(0);
            }
        });

        return inflate;
    }
}
